package com.cdream.basic.algorithm.leetcode.findElement;

import java.util.HashSet;
import java.util.Set;

/**
 * @author cdream
 * @date 5/22/21
 */
public class Question349 {
    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> set1 = new HashSet<>();
        Set<Integer> res = new HashSet<>();

        for (int i1 : nums1) {
            set1.add(i1);
        }

        for (int i1 : nums2) {
            if (set1.contains(i1)) {
                res.add(i1);
            }
        }
        int[] resArray = new int[res.size()];
        int count = 0;
        for (Integer re : res) {
            resArray[count++] = re;
        }
        return resArray;
    }
}
